package com.tbit.uqbike.webmanager.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.tbit.common.entity.view.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 提供给前端转发接口
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2024-9-23
 */
@RestController
@RequestMapping("/webFront")
@Slf4j
public class WebController {


    @PostMapping("/uploadImage")
    public Result<Object> getMapImage(String image,Integer index, String taskId){
        try {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("image", image);
            requestMap.put("index", index);
            requestMap.put("taskId",taskId);
            HttpResponse response = HttpRequest.post("http://imageprocessing.uqbike.cn/upload-image").body(JSON.toJSONString(requestMap)).execute();
            return Result.success(JSON.parseObject(response.body(), Map.class));
        }catch (Exception e){
            log.error("调用getMapImage失败", e);
        }
        return Result.error();
    }


    @PostMapping("/combineImages")
    public Result<Object> getCombine(String taskId,Integer rows, Integer columns){
        try {
            Map<String, Object> requestMap = new HashMap<>();
            requestMap.put("taskId",taskId);
            requestMap.put("rows",rows);
            requestMap.put("columns",columns);
            HttpResponse response = HttpRequest.post("http://imageprocessing.uqbike.cn/combine-images").body(JSON.toJSONString(requestMap)).execute();
            return Result.success(JSON.parseObject(response.body(), Map.class));
        }catch (Exception e){
            log.error("调用getCombine失败", e);
        }
        return Result.error();
    }
}
